import { getPosition } from "@/api/geo";
const geo = {
    state: { position: {} },
    
    mutations: {
      setPosition: (state, val) => {
        state.position = val;
      }
    },
    
    actions: {
      setPosition: ({ commit }) => {
        return new Promise((resolve, reject) => {
          getPosition()
            .then(response => {
              const status = response.status;
              const city = response.data.result.ad_info.city;
              const province = response.data.result.ad_info.province;
              commit("setPosition", status===200?{city,province}:{city:'',province:''});
              resolve();
            })
            .catch(error => {
              reject(error);
            });
        });
      }
    }

}

export default geo;
